package com.zmz.Stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Create with IntelliT IDEA
 *
 * @Author: zhengmingzhe
 * @Date: 2022/07/31/18:18
 * @Description: Collection提供了一系列用于数据统计的静态方法：
 */
public class Stream09 {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<>();
        personList.add(new Person("的撒", 8000, 22, "女", "武汉"));
        personList.add(new Person("法按时", 7000, 22, "女", "武汉"));
        personList.add(new Person("的阿萨", 7800, 22, "男", "武汉"));
        personList.add(new Person("答案", 12000, 12, "女", "武汉"));
        personList.add(new Person("滴放", 22000, 21, "女", "北京"));

        //统计员工人数输出5
        Long count = personList.stream().count();
        System.out.println(count);
        Long collect =personList.stream().collect(Collectors.counting());
        System.out.println(collect);
        //求平均工资输出11360.0
        Double avgSalary = personList.stream().collect(Collectors.averagingInt(Person::getSalary));
        System.out.println(avgSalary);
        //求最高工资1输出22000
        Integer max1 = personList.stream().map(p->p.getSalary()).reduce(Integer::max).get();
        System.out.println(max1);
        //求最高工资2输出22000
        Integer max2 = personList.stream().map(p->p.getSalary()).collect(Collectors.maxBy(Integer::compareTo)).get();
        System.out.println(max2);
        //求工资之和 输出56800
        Long sum1 = personList.stream().collect(Collectors.summingLong(Person::getSalary));
        System.out.println(sum1);
        //一次性统计所有东西(总数,最大值，最小值，平均值，最大值) 输出IntSummaryStatistics{count=5, sum=56800, min=7000, average=11360.000000, max=22000}
        IntSummaryStatistics collect1 = personList.stream().collect(Collectors.summarizingInt(Person::getSalary));
        System.out.println(collect1);


    }



}
